﻿using Utils.Extensions;

namespace StockAnalyst2.Options
{
	internal static class ApplicationOptionsDataSource
	{
		public static ApplicationOptions Load()
		{
			ApplicationOptions result = new ApplicationOptions(Properties.Settings.Default.UserName,
			                                                   Properties.Settings.Default.Password.Decrypt(),
			                                                   Properties.Settings.Default.DatabaseServer,
			                                                   Properties.Settings.Default.DatabaseName,
															   Properties.Settings.Default.RealTimeEnabled);

			return result;
		}

		public static void Save(ApplicationOptions applicationOptions)
		{
			Properties.Settings.Default.UserName = applicationOptions.UserName;
			Properties.Settings.Default.Password = applicationOptions.Password.Crypt();
			Properties.Settings.Default.DatabaseServer = applicationOptions.DatabaseServer;
			Properties.Settings.Default.DatabaseName = applicationOptions.DatabaseName;
			Properties.Settings.Default.RealTimeEnabled = applicationOptions.RealTimeEnabled;
			Properties.Settings.Default.Save();
		}
	}
}
